package app.search.client;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.*;

public class ClassDataSource extends DataSource {

    private static ClassDataSource instance = null;

    public static ClassDataSource getInstance() {
        if (instance == null) {
            instance = new ClassDataSource("classDataSource");
        }
        return instance;
    }

    public ClassDataSource(String id) {

        setID(id);
        //setRecordXPath("/List/class");
        setRecordXPath("//class");

        DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
        pkField.setHidden(true);
        pkField.setPrimaryKey(true);
        DataSourceTextField nameField = new DataSourceTextField("name", "name");
        nameField.setRequired(true);
        DataSourceTextField sportField = new DataSourceTextField("sport", "sport");
        sportField.setRequired(true);
        DataSourceTextField addressField = new DataSourceTextField("address", "address");
        addressField.setRequired(true);
        DataSourceTextField cityField = new DataSourceTextField("city", "city");
        cityField.setRequired(true);
        DataSourceTextField stateField = new DataSourceTextField("state", "state");
        stateField.setRequired(true);
        DataSourceTextField zipField = new DataSourceTextField("zip", "zip");
        zipField.setRequired(true);
        DataSourceTextField phoneField = new DataSourceTextField("phone", "phone");
        phoneField.setRequired(true);
        DataSourceTextField timeField = new DataSourceTextField("time", "time");
        timeField.setRequired(true);
        setFields(pkField, nameField, sportField, addressField, cityField, stateField, phoneField, timeField);


/*
        DataSourceIntegerField pkField = new DataSourceIntegerField("@key");
        pkField.setHidden(true);
        pkField.setPrimaryKey(true);
        DataSourceTextField nameField = new DataSourceTextField("name", "LOCATIONS/@lcLocation");
        nameField.setRequired(true);
        DataSourceTextField sportField = new DataSourceTextField("sport", "@clSptype");
        sportField.setRequired(true);
        DataSourceTextField addressField = new DataSourceTextField("address", "LOCATIONS/@lcAddressPrimary1");
        addressField.setRequired(true);
        DataSourceTextField cityField = new DataSourceTextField("city", "LOCATIONS/@city");
        cityField.setRequired(true);
        DataSourceTextField stateField = new DataSourceTextField("state", "LOCATIONS/@state");
        stateField.setRequired(true);
        DataSourceTextField zipField = new DataSourceTextField("zip", "LOCATIONS/@lcZip");
        zipField.setRequired(true);
        DataSourceTextField phoneField = new DataSourceTextField("phone", "LOCATIONS/@lcZip");
        phoneField.setRequired(true);
        DataSourceTextField timeField = new DataSourceTextField("time", "@clStartTime");
        timeField.setRequired(true);
        setFields(pkField, nameField, sportField, addressField, cityField, stateField, phoneField, timeField);
*/

        setDataURL("/search/list");
        setClientOnly(true);
    }
}
